package com.jf3q.front.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jf3q.common.domain.EduComment;
import com.jf3q.common.vo.ResultVo;
import com.jf3q.front.service.EduCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    EduCommentService eduCommentService;

    @PostMapping("/Select")
    public ResultVo pages(@RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = Integer.MAX_VALUE+"")Integer pageSize,
                          @RequestBody EduComment eduComment,
                          String MemberId){
        LambdaQueryWrapper<EduComment> queryWrapper=new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(eduComment.getNickname())){
            queryWrapper.like(EduComment::getNickname,eduComment.getNickname());
        }
        if (!ObjectUtils.isEmpty(MemberId)){
            queryWrapper.eq(EduComment::getMemberId,MemberId);
        }
        Page<EduComment> page=eduCommentService.page(new Page<>(pageNum,pageSize),queryWrapper);
        return ResultVo.success("查询评论成功！",page);
    }

    //删除评论信息
    @DeleteMapping("/{id}")
    public ResultVo delete(@PathVariable String id){
        eduCommentService.removeById(id);
        return ResultVo.success("删除成功！",null);
    }


    //更改评论信息
    @PostMapping("/save")
    public ResultVo saves(@RequestBody EduComment eduComment){
       eduCommentService.saveOrUpdate(eduComment);
       return ResultVo.success("操作成功！",null);
    }
}
